<?php include "../public/header.php";?>
<?php include "../public/header_edit.php";?>
<link rel="stylesheet" type="text/css" href="/static/component/laytp/module/cityPicker/city-picker.css">

<body id="optPage">
<form class="layui-form layui-form-pane" id="commentForm">
    <div class="page-title">
        <div class="page-title-con">
            <span id="flowsetname"></span>
            <div class="move_title"></div>
            <div class="page-title-opt-list">
                <button type="button" class="layui-btn layui-btn-sm btn-light marginr5" onclick="check_bid()">从中标项目引入</button>
                <button type="button" class="layui-btn layui-btn-sm btn-light marginr5" id="billzhan" but="1" key="0" lay-submit="" lay-filter="add">暂存</button>
                <button type="button" class="layui-btn layui-btn-sm btn-light marginr5" id="billtutn" but="2" key="0" lay-submit="" lay-filter="add">保存草稿</button>
                <button type="button" class="layui-btn layui-btn-sm btn-dark marginr5" but="3" key="1" id="billsub" isshen="0" lay-submit="" lay-filter="add">提交审核</button>
                <span id="page-close" class="page-close" onclick="layer_close()">×</span>
            </div>
        </div>
    </div>
    <div class="main-container">
        <div class="block-generic">
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">申请人</label>
                        <div class="layui-input-block">
                            <input type="text" id="flowuser" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">申请部门</label>
                        <div class="layui-input-block">
                            <input type="text" id="flowdept" readonly placeholder="请输入" autocomplete="off" class="layui-input readonly">
                        </div>
                    </div>
                </div>
            </div>


            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="edittits"><span>基本信息</span></div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>承揽状态</label>
                        <div class="layui-input-block">
                            <select id="lantake" name="lantake" lay-filter="lantake" ></select>
                            <p class="error" id="lantake_error" style="margin: 0;"></p>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>工程名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="name" id="name" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">工程编号</label>
                        <div class="layui-input-block">
                            <input type="text" name="number" id="number" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>甲方名称</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="jiaer" class="layui-input jiaer" onclick="openPage('../public/choose_dealcom.php?dom=jiaer','80%','80%')">
                            <div class="choose_div" id="jiaer" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_dealcom.php?dom=jiaer','80%','80%')"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">工程负责人</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="gofuer" class="layui-input gofuer" onclick="openPage('../public/choose_dealcom.php?dom=gofuer','80%','80%')">
                            <div class="choose_div" id="gofuer" key="0"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_dealcom.php?dom=gofuer','80%','80%')"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">所在地</label>
                        <div class="layui-input-block" style="z-index: 1;">
                            <input type="text" name="areas" id="areas" placeholder="请选择" readonly clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">详细地址</label>
                        <div class="layui-input-block">
                            <input type="text" name="addr" id="addr" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>承揽方式</label>
                        <div class="layui-input-block">
                            <div id="lanshi"></div>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>业务归属</label>
                        <div class="layui-input-block">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=gui_unit&type=dept&dept=chan&single=1','770px','490px');"></div>
                                <div class="tanxiannei" id="gui_unit"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=gui_unit&type=dept&dept=chan&single=1','770px','490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                            <div id="gui_unit_tanerror" class="tanerrormsg"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text class="takehide layui-hide">*</text>招标方式</label>
                        <div class="layui-input-block">
                            <div id="zhaotype"></div>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text class="takehide layui-hide">*</text>工程发布平台</label>
                        <div class="layui-input-block">
                            <div id="kailei"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">资质要求</label>
                        <div class="layui-input-block">
                            <input type="text" name="gongzi" id="gongzi" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>工程内容</label>
                        <div class="layui-input-block">
                            <input type="text" name="gongnei" id="gongnei" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>工程建设规模</label>
                        <div class="layui-input-block">
                            <input type="text" name="guimo" id="guimo" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text class="takehide layui-hide">*</text>中标单位</label>
                        <div class="layui-input-block">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=win_unit&type=dept&dept=chan&single=1','770px','490px');"></div>
                                <div class="tanxiannei" id="win_unit"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=win_unit&type=dept&dept=chan&single=1','770px','490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                            <div id="win_unit_tanerror" class="tanerrormsg"></div>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">中标日期</label>
                        <div class="layui-input-block">
                            <input type="text" name="windt" id="windt" readonly placeholder="请选择" clearable  autocomplete="off" class="layui-input bdate_ymd">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">中标价(元)</label>
                        <div class="layui-input-block">
                            <input type="text" id="winfee" name="winfee" placeholder="请输入" clearable autocomplete="off" class="layui-input moneyinput">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">工期(天)</label>
                        <div class="layui-input-block ">
                            <input type="text" name="gongqi" id="gongqi" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label">劳务分包服务费率(%)</label>
                        <div class="layui-input-block">
                            <input type="number" name="ratefu" id="ratefu" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">税款保证金费率(%)</label>
                        <div class="layui-input-block">
                            <input type="number" name="rateshui" id="rateshui" placeholder="请输入" clearable autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md6">
                        <label class="layui-form-label"><text>*</text>工程状态</label>
                        <div class="layui-input-block">
                            <select id="state" name="state" lay-filter="state" ></select>
                            <p class="error" id="state_error" style="margin: 0;"></p>
                        </div>
                    </div>
                    <div class="layui-col-md6">
                        <label class="layui-form-label">工程合同类别</label>
                        <div class="layui-input-block">
                            <div id="gonghelei"></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item height_auto">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label label_textarea">备注</label>
                        <div class="layui-input-block">
                            <textarea id="explain" name="explain" placeholder="请输入" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">关联流程</label>
                        <div class="layui-input-block">
                            <input type="text" readonly name="flowrelas" class="layui-input flowrelas" onclick="openPage('../public/choose_flowrelas.php?dom=flowrelas','80%','80%');">
                            <div class="choose_div" id="flowrelas" key="1"></div>
                            <span class="choose_one" onclick="openPage('../public/choose_flowrelas.php?dom=flowrelas','80%','80%');"><i class="layui-icon layui-icon-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-hide" id="advanersDiv">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label">预审人</label>
                        <div class="layui-input-block relative">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=advaners&type=user&single=2','770px','490px');"></div>
                                <div class="tanxiannei" id="advaners"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=advaners&type=user&single=2','770px','490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-hide" id="nexterDiv">
                <div class="layui-row layui-col-space10">
                    <div class="layui-col-md12">
                        <label class="layui-form-label"><text>*</text>指定下一步审核人</label>
                        <div class="layui-input-block relative">
                            <div class="tanxian">
                                <div class="tanxianclick" onclick="openPage('../public/choose_userpart.php?dom=nexter&type=user&single=1','770px','490px');"></div>
                                <div class="tanxiannei" id="nexter"></div>
                            </div>
                            <div class="tancheckdiv"><div class="tancheck" onclick="openPage('../public/choose_userpart.php?dom=nexter&type=user&single=1','770px','490px');"><i class="layui-icon layui-icon-search"></i></div></div>
                        </div>
                    </div>
                </div>
            </div>
            <?php include '../public/upinfo.php'?>

        </div>
    </div>
</form>
<script>
    var param_bidid = getQueryVariable('bidid') || 0;


    $("#commentForm").validate({
        rules: {
            name: {required: true},
            gongnei: {required: true},
            guimo: {required: true},
        },
        messages:{
            name: {required: "请输入"},
            gongnei: {required: "请输入"},
            guimo: {required: "请输入"},
        }
    });


    function check_bid () {
        openPage('../public/choose_bid_yin.php?','80%','80%');
    }



    function yinru_bid_files(bidid) {
        facade.ajax({url: ask_engin_yinbidfile, data:{bidid:bidid}}).done(function(res){
            if (res.code === 2000) {
                public_upload_file_load('upload_files', res.data.files);
                render_from();
            }
        });
    }


    var pub_lantake, pub_state, pub_areas, pub_lanshi, pub_kailei, pub_zhaotype;
    layui.use(['laytp', 'form'], function() {
        var form = layui.form, layer = layui.layer;
        render_input_attr();

        facade.ajax({type: 'get', url: ask_flowdata_add_engin, data:{bidid:param_bidid}}).done(function(res){
            if (res.code === 2000) {
                var data = res.data;
                $("#flowsetname").text(data.flowsetname);
                $("#flowuser").val(data.flowuser);
                $("#flowdept").val(data.flowdept);
                if(data.isadvan){
                    $("#advanersDiv").removeClass('layui-hide');
                }
                if(data.isnext){
                    $("#nexterDiv").removeClass('layui-hide');
                }


                pub_lantake = res.data.lantake;
                pub_state = res.data.state;
                pub_areas = res.data.areas;
                pub_lanshi = res.data.lanshi;
                pub_kailei = res.data.kailei;
                pub_zhaotype = res.data.zhaotype;


                var bidinfo = res.data.data;
                if(bidinfo){
                    $('#name').val(bidinfo.name);
                    $('#number').val(bidinfo.number);
                    if(bidinfo.jiaer){
                        set_choose_btn('jiaer',bidinfo.jiaer,bidinfo.jiaer);
                    }
                    $('#addr').val(bidinfo.addr);
                    $('#windt').val(bidinfo.windt);
                    $('#winfee').val(bidinfo.winfee);
                    $('#gongqi').val(bidinfo.gongqi);
                    $('#explain').val(bidinfo.explain);



                    if(bidinfo.win_unit_info.length > 0){
                        tan_tags_init('#win_unit', bidinfo.win_unit_info);
                    }
                    if(bidinfo.gui_unit_info.length > 0){
                        tan_tags_init('#gui_unit', bidinfo.gui_unit_info);
                    }

                    if(bidinfo.gofuer){
                        set_choose_btn('gofuer',bidinfo.gofuer,bidinfo.gofuer);
                    }


                    var lantake_str = '<option value="">请选择</option>';
                    var lantake = res.data.lantake;
                    for (var key in lantake){
                        if(bidinfo.lantake == key){
                            lantake_str += '<option value="'+key+'" selected>'+lantake[key]+'</option>';
                        }else{
                            lantake_str += '<option value="'+key+'">'+lantake[key]+'</option>';
                        }
                    }
                    $("#lantake").html(lantake_str);


                    var state_str = '<option value="">请选择</option>';
                    var state = res.data.state;
                    for (var key in state){
                        if(bidinfo.state == key){
                            state_str += '<option value="'+key+'" selected>'+state[key]+'</option>';
                        }else{
                            state_str += '<option value="'+key+'">'+state[key]+'</option>';
                        }
                    }
                    $("#state").html(state_str);

                    $("#areas").val(bidinfo.areas);
                    load_areas('areas', res.data.areas, 3);
                    xmselect_dan('lanshi', res.data.lanshi, bidinfo.lanshi, function (res) {
                        if(res.arr && res.arr.length > 0){
                            $("#lanshi").find('xm-select').removeClass('error');
                        }else{
                            $("#lanshi").find('xm-select').addClass('error');
                        }
                    });
                    xmselect_dan('kailei', res.data.kailei, bidinfo.kailei, function (res) {
                        if(res.arr && res.arr.length > 0){
                            $("#kailei").find('xm-select').removeClass('error');
                        }else{
                            $("#kailei").find('xm-select').addClass('error');
                        }
                    });
                    xmselect_dan('zhaotype', res.data.zhaotype, bidinfo.zhaotype, function (res) {
                        if(res.arr && res.arr.length > 0){
                            $("#zhaotype").find('xm-select').removeClass('error');
                        }else{
                            $("#zhaotype").find('xm-select').addClass('error');
                        }
                    });
                }else{

                    var lantake_str = '<option value="">请选择</option>';
                    var lantake = res.data.lantake;
                    for (var key in lantake){
                        if(data.lantake == key){
                            lantake_str += '<option value="'+key+'" selected>'+lantake[key]+'</option>';
                        }else{
                            lantake_str += '<option value="'+key+'">'+lantake[key]+'</option>';
                        }
                    }
                    $("#lantake").html(lantake_str);


                    var state_str = '<option value="">请选择</option>';
                    var state = res.data.state;
                    for (var key in state){
                        if(data.state == key){
                            state_str += '<option value="'+key+'" selected>'+state[key]+'</option>';
                        }else{
                            state_str += '<option value="'+key+'">'+state[key]+'</option>';
                        }
                    }
                    $("#state").html(state_str);



                    load_areas('areas', res.data.areas, 3);
                    xmselect_dan('lanshi', res.data.lanshi, '', function (res) {
                        if(res.arr && res.arr.length > 0){
                            $("#lanshi").find('xm-select').removeClass('error');
                        }else{
                            $("#lanshi").find('xm-select').addClass('error');
                        }
                    });
                    xmselect_dan('kailei', res.data.kailei, '', function (res) {
                        if(res.arr && res.arr.length > 0){
                            $("#kailei").find('xm-select').removeClass('error');
                        }else{
                            $("#kailei").find('xm-select').addClass('error');
                        }
                    });
                    xmselect_dan('zhaotype', res.data.zhaotype, '', function (res) {
                        if(res.arr && res.arr.length > 0){
                            $("#zhaotype").find('xm-select').removeClass('error');
                        }else{
                            $("#zhaotype").find('xm-select').addClass('error');
                        }
                    });

                }


                xmselect_dan('gonghelei', res.data.gonghelei, '');




                public_upload_file_load('upload_files', res.data.files);
                render_date();
                render_from();
                initParseMoney();
            }
        });


        form.on('select(lantake)', function(data){
            if(data.value == ''){
                $('#lantake_error').show().text('请选择');
                $('#lantake_error').parent().find('input').addClass('select_error');
            }else{
                $('#lantake_error').hide();
                $('#lantake_error').parent().find('input').removeClass('select_error');
            }

            if(data.value == 2){
                $(".takehide").removeClass('layui-hide');
            }else{
                $(".takehide").addClass('layui-hide');
            }
            render_from();
        });

        form.on('select(state)', function(data){
            if(data.value == ''){
                $('#state_error').show().text('请选择');
                $('#state_error').parent().find('input').addClass('select_error');
            }else{
                $('#state_error').hide();
                $('#state_error').parent().find('input').removeClass('select_error');
            }
        });

        form.on('submit(add)', function(data){
            data.field.isturn = $(this).attr('key') || 0;
            data.field.flowrelas = get_choose_val('flowrelas');
            data.field.advaners = tan_tags_getvalue("#advaners", 'user');
            data.field.nexter = tan_tags_getvalue("#nexter", 'user');

            data.field.jiaer = get_choose_val('jiaer');
            data.field.gofuer = get_choose_val('gofuer');
            data.field.gui_unit = tan_tags_getvalue("#gui_unit", 'dept');
            data.field.win_unit = tan_tags_getvalue("#win_unit", 'dept');

            if(data.field.isturn > 0){
                var validRes = $("#commentForm").valid();

                formValid('jiaer');
                if(data.field.jiaer == undefined || !data.field.jiaer){
                    validRes = false;
                }

                if(data.field.lantake == ''){
                    $('#lantake_error').show().text('请选择');
                    $('#lantake_error').parent().find('input').addClass('select_error');
                    validRes = false;
                }else{
                    $('#lantake_error').hide();
                    $('#lantake_error').parent().find('input').removeClass('select_error');
                }

                if(!data.field.gui_unit){
                    $("#gui_unit").parents('.tanxian').addClass('tanerror');
                    $('#gui_unit_tanerror').text('请选择');
                    validRes = false;
                }else{
                    $("#gui_unit").parents('.tanxian').removeClass('tanerror');
                    $('#gui_unit_tanerror').text('');
                }

                if(!data.field.lanshi){
                    $("#lanshi").find('xm-select').addClass('error');
                    validRes = false;
                }else{
                    $("#lanshi").find('xm-select').removeClass('error');
                }



                if(!data.field.kailei && data.field.lantake == 2){
                    $("#kailei").find('xm-select').addClass('error');
                    validRes = false;
                }else{
                    $("#kailei").find('xm-select').removeClass('error');
                }

                if(!data.field.zhaotype && data.field.lantake == 2){
                    $("#zhaotype").find('xm-select').addClass('error');
                    validRes = false;
                }else{
                    $("#zhaotype").find('xm-select').removeClass('error');
                }

                if(!data.field.win_unit && data.field.lantake == 2){
                    $("#win_unit").parents('.tanxian').addClass('tanerror');
                    $('#win_unit_tanerror').text('请选择');
                    validRes = false;
                }else{
                    $("#win_unit").parents('.tanxian').removeClass('tanerror');
                    $('#win_unit_tanerror').text('');
                }

                if(data.field.state == ''){
                    $('#state_error').show().text('请选择');
                    $('#state_error').parent().find('input').addClass('select_error');
                    validRes = false;
                }else{
                    $('#state_error').hide();
                    $('#state_error').parent().find('input').removeClass('select_error');
                }

                if(!validRes){return false;}
            }


            data.field.bidid = param_bidid;
            data = parseMoney(data);
            data.field.files = public_upload_file_value('upload_files');
            public_flow_submit(data.field, ask_flowdata_add_engin, ask_flowdata_edit_engin, $(this).attr('but'));
            return false;
        });

    });

</script>
</body>
</html>
